package com.atguigu.process.service.impl;

import com.atguigu.model.process.ProcessTemplate;
import com.atguigu.model.process.ProcessType;
import com.atguigu.process.mapper.OaProcessTypeMapper;
import com.atguigu.process.service.OaProcessTemplateService;
import com.atguigu.process.service.OaProcessTypeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 审批类型 服务实现类
 * </p>
 *
 * @author 赵星
 * @since 2023-12-21
 */
@Service
public class OaProcessTypeServiceImpl extends ServiceImpl<OaProcessTypeMapper, ProcessType> implements OaProcessTypeService {
    @Autowired
    private OaProcessTemplateService processTemplateService;


    //获取全部审批分类及模版
    @Override
    public List<ProcessType> findProcessType() {
        //获取所有审批类型
        List<ProcessType> processTypes = baseMapper.selectList(null);
        //根据审批类型id获取审批模版
        for (ProcessType processType : processTypes) {
            LambdaQueryWrapper<ProcessTemplate> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(ProcessTemplate::getProcessTypeId, processType.getId());
            List<ProcessTemplate> processTemplateList = processTemplateService.list();
            //将查出的审批模版封装到ProcessType
            processType.setProcessTemplateList(processTemplateList);
        }
        return processTypes;
    }
}
